$(function() {
 mygrid = $("#list").jqGrid({
		url : 'admin/role/role!datalist',
		datatype : "json",
		mtype : 'GET',
		colNames : [ '查看', '管理' ],
		colModel : [ {
			name : 'id',
			index : 'id',
			width : 300,
			formatter : viewFormater
		}, {
			name : 'id',
			index : 'id',
			width : 50,
			formatter : removeFormatter
		}, ],
		pager : '#pager',
		rowNum : 10,
		rowList : [ 10, 20, 30 ],
		sortname : 'name',
		sortorder : 'desc',
		viewrecords : true,
		caption : '职务列表',
		width : '500',
		height : '300',
		jsonReader : {
			repeatitems : false,
			id : "0"
		}
	}).jqGrid("navGrid", "#pager", {
		edit : false,
		add : false,
		del : false,
		search : false
	}).jqGrid("navButtonAdd", "#pager", {
		onClickButton : function() {
			doAjaxLink('admin/role/input?action=add!add');
		},
		buttonicon : "ui-icon-newwin",
		caption : "添加新角色",
		id : "newGroup"
	});

});
function viewFormater(cellvalue, options, rowObject) {
	var eid = rowObject['id'];
	var url = 'admin/role/role!get?bean.id=' + cellvalue;
	var link = $(getAjaxLink(url, rowObject['name']));
	return $("<span></span>").append(link).html();

}
function removeFormatter(val, opt, row) {
	var url = 'admin/role/role!remove?bean.id=' + val;
	var link = $("<a href=\"javascript:removeRole('"+url+"');\">删除</a>");
	return $("<span></span>").append(link).html();
}
function removeRole(url){
	$.ajax({
		url:url,
		success:function(){
			mygrid.trigger("reloadGrid");
		}
	})
}